package com.itxiaoxiong.chat.controller;

import com.itxiaoxiong.chat.pojo.ChatMessage;
import com.itxiaoxiong.chat.pojo.Result;
import com.itxiaoxiong.chat.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
public class FileController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    /*
    上传文件到阿里云服务器
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile image) throws IOException {
        log.info("文件上传,文件名:{}", image.getOriginalFilename());
        //调用阿里云OSS工具类进行文件上传
        String url = aliOSSUtils.upload(image);
        log.info("文件上传完成，文件访问的url: {}", url);

        return Result.success(url);
    }

}
